<?php include('../resources/views/header.blade.php'); ?>

<style type="text/css">
    .add_question_input{
        padding: 0 ;
        width: 94% ;
        border-style: none ;
        margin-left: 3% ;
        margin-right: 3% ;
        border-radius: 0px ;
        outline: none ;
        font-size: 16px ;
        line-height: 30px;
        background-color: #F8F9FA ;
        border-bottom: 2px solid #ccc ;
    }
    .add_question_input:focus {
        padding: 0 ;
        width: 94% ;
        border-style: none ;
        margin-left: 3% ;
        margin-right: 3% ;
        border-radius: 0px ;
        outline: none ;
        font-size: 16px ;
        line-height: 30px;
        background-color: #F8F9FA ;
        border-bottom: 2px solid #58bdfd ;
    }

    .add_question_radio {
        -webkit-appearance: radio;
        height: 16px;
        vertical-align: top;
    }
</style>



<section>
    <div style="float:right;margin-right:12px;">
        <button class="button mcolor" id="commit_question" style="height:30px;padding-top:4px;padding-bottom:4px;background-color:#eee;">提交问题</button>
    </div>
    <p style="padding-left:12px;font-size:18px;">添加问题</p>
</section>

<section style="margin-top:48px;">
    <textarea class="add_question_input" id="new_question_title" style="height:36px;" placeholder="问题标题"></textarea>
</section>

<section style="margin-top:36px;">
    <textarea class="add_question_input" id="new_question_desc" placeholder="问答描述"></textarea>
</section>

<section style="margin-top:36px;font-size:16px;padding-left:12px;">
    <p style="color:#888;font-size:14px;margin:0;margin-bottom:6px;">问题所属话题</p>
    <?php
        if( isset($topics) ){
            foreach( $topics as $key => $val ){
                if( $key == 0 ){
                    echo '<p><input class="add_question_radio" id="radio'.$val->id.'" name="question_topic" type="radio" value="1" checked="checked" /><label for="radio1" >'.$val->name.'</label></p>';
                }else{
                    echo '<p><input class="add_question_radio" id="radio'.$val->id.'" name="question_topic" type="radio" value="2" /><label for="radio2" >'.$val->name.'</label></p>';
                }
            }
        }
    ?>
</section>

<?php include('../resources/views/footer.blade.php'); ?>

<script type="text/javascript">
    $("#commit_question").on('click',function(){
        var title       = $("#new_question_title").val();
        var description = $("#new_question_desc").val();
        var topic       = $('input[name="question_topic"]:checked').val();
        if( title == '' ){
            toast("请填写新建问题标题");return ;
        }
        if( description == '' ){
            toast("请填写新建问题描述");return ;
        }
        if( topic == '' ){
            toast("请选择新建问题所属话题");return ;
        }
        $.ajax({
            type: "post" ,
            url: "/question" ,
            data: {"title":title , "description":description , "topic":topic} ,
            dataType: "json" ,
            success: function(data){
                if( data.error ){
                    toast(data.message);
                }else{
                    toast("新建成功");
                    window.history.back(-1);
                }
            }
        });
    });
</script>
